﻿Imports System.Data
Imports System.Data.SqlClient
Public Class NguoiChoThue_DAO
    Public Shared Function LoadNguoiChoThue() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()

        Dim cm As SqlCommand = New SqlCommand("LoadNhaChoThue", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadDuLieuLenCMBData() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("LoadLoaiNhaChothue", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadMaNha() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("loadmanha", cn)
        cm.CommandType = CommandType.StoredProcedure
        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadThongTinTimKiemGia(ByVal giamax As Integer, ByVal giamin As Integer) As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("tiemkiemtheogia", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.AddWithValue("@giamax", giamax)
        cm.Parameters.AddWithValue("@giamin", giamin)

        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadThongTinTimkiemNguoiO(ByVal SL As Integer) As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("timkiemthesonguoio", cn)
        cm.CommandType = CommandType.StoredProcedure

        cm.Parameters.AddWithValue("@songuoi", SL)

        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadThongTinTimkiemdiachi(ByVal DiaChi As String) As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("timkiemtheodiachi", cn)
        cm.CommandType = CommandType.StoredProcedure

        cm.Parameters.AddWithValue("@diachi", DiaChi)

        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadGia() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Loadgia", cn)
        cm.CommandType = CommandType.StoredProcedure

        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function
    Public Shared Function LoadGia1() As DataTable
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim cm As SqlCommand = New SqlCommand("Loadgia1", cn)
        cm.CommandType = CommandType.StoredProcedure

        Dim da As SqlDataAdapter = New SqlDataAdapter(cm)
        Dim bang As DataTable = New DataTable()
        da.Fill(bang)
        cn.Close()
        Return bang
    End Function

    Public Shared Function ChenDuLieuNguoiChoThue(ByVal NguoiChoThue As NguoiChoThue_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("ThemNguoiChoThue", cn)
        cm.CommandType = CommandType.StoredProcedure
        'Dim id As Integer = TaoIDTuDong()

        cm.Parameters.AddWithValue("@hoten", NguoiChoThue.TenNguoiChoThue)
        cm.Parameters.AddWithValue("@diachi", NguoiChoThue.DiaChiChothue)
        cm.Parameters.AddWithValue("@giachothue", NguoiChoThue.GiaChothue)
        cm.Parameters.AddWithValue("@dienthoai", NguoiChoThue.DienThoaiChoThue)
        cm.Parameters.AddWithValue("@songuoio", NguoiChoThue.SoNguoiO)
        cm.Parameters.AddWithValue("@maloainha", NguoiChoThue.MaLoaiNha)
        cm.Parameters.AddWithValue("@mieuta", NguoiChoThue.MieuTaNha)
        cm.Parameters.AddWithValue("@tieude", NguoiChoThue.TieuDe)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function UpdateDuLieuNguoiChoThue(ByVal NguoiChoThue1 As NguoiChoThue_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("updatethongtinnguoichothue", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.AddWithValue("@manha", NguoiChoThue1.MaNha)
        cm.Parameters.AddWithValue("@hoten", NguoiChoThue1.TenNguoiChoThue)
        cm.Parameters.AddWithValue("@diachi", NguoiChoThue1.DiaChiChothue)
        cm.Parameters.AddWithValue("@giachothue", NguoiChoThue1.GiaChothue)
        cm.Parameters.AddWithValue("@dienthoai", NguoiChoThue1.DienThoaiChoThue)
        cm.Parameters.AddWithValue("@songuoio", NguoiChoThue1.SoNguoiO)
        'cm.Parameters.AddWithValue("@maloainha", "NULL")
        cm.Parameters.AddWithValue("@mieuta", NguoiChoThue1.MieuTaNha)
        cm.Parameters.AddWithValue("@tieude", NguoiChoThue1.TieuDe)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function deleteDuLieuNguoiChoThue(ByVal MaNguoiChoThue As Integer) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("deletethongtinnguoichothue", cn)
        cm.CommandType = CommandType.StoredProcedure
        cm.Parameters.AddWithValue("@manha", MaNguoiChoThue)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
    Public Shared Function LayDLExcelNguoiChoThue(ByVal NguoiChoThue1 As NguoiChoThue_DTO) As Boolean
        Dim cn As SqlConnection = DataProvider.KetNoi()
        Dim check As Boolean = True
        Dim cm As SqlCommand = New SqlCommand("LayDLExeclnguoichothue ", cn)
        cm.CommandType = CommandType.StoredProcedure

        cm.Parameters.AddWithValue("@hoten", NguoiChoThue1.TenNguoiChoThue)
        cm.Parameters.AddWithValue("@diachi", NguoiChoThue1.DiaChiChothue)
        cm.Parameters.AddWithValue("@giachothue", NguoiChoThue1.GiaChothue)
        cm.Parameters.AddWithValue("@dienthoai", NguoiChoThue1.DienThoaiChoThue)
        cm.Parameters.AddWithValue("@songuoio", NguoiChoThue1.SoNguoiO)
        cm.Parameters.AddWithValue("@mieuta", NguoiChoThue1.MieuTaNha)
        cm.Parameters.AddWithValue("@tieude", NguoiChoThue1.TieuDe)

        Try
            cm.ExecuteNonQuery()

            cn.Close()
        Catch ex As Exception
            cn.Close()
            check = False

        End Try
        Return (check)
    End Function
End Class
